#include <iostream>
#include <string.h>
using namespace std;
/*
检测字符串s中有多少个不同的字符，这里假定字符串只包含数字
*/
int findMany(char s[])
{
    bool find[10] ={};
    for(int i = 0; i<strlen(s); i++)
        find[s[i]-'0'] = true;
    int counter = 0;
    for(int i = 0; i < 10; i++)
    {
        if(find[i] == true)
           counter = counter + 1;
    }
    return counter; 
}

int main()
{
    //获取输入
    int y,n;
    cin>>y>>n;
    //从y年开始，暴力搜索
    int curYear = y;
    while(true)
    {
        char year[5];
        sprintf(year,"%04d",curYear);
        if(findMany(year) == n)
            break;
        curYear = curYear + 1;
    }
    //发现后输出结果
    char year[5];
    sprintf(year,"%04d",curYear);
    cout<<curYear - y<<" "<<year;
}